package main

import (
	"fmt"
	"github.com/gin-gonic/gin"
	ratelimit2 "github.com/juju/ratelimit" // 令牌桶
	ratelimit1 "go.uber.org/ratelimit"     // 漏桶
	"net/http"
)

func pingHandler(c *gin.Context) {
	c.String(http.StatusOK, "pong!")
}

func helloHandler(c *gin.Context) {
	c.String(http.StatusOK, "hello world!")
}

// 基于漏桶的限流中间件1
func rateLimit() gin.HandlerFunc {
	return func(c *gin.Context) {
		r := ratelimit1.New(100)
		fmt.Println(r)
	}
}

// 基于令牌桶的限流中间件2
func rateLimit2() gin.HandlerFunc {
	return func(c *gin.Context) {
		//ratelimit2.
	}
}

func main() {
	r := gin.Default()
	r.GET("ping", pingHandler)
	r.GET("hello", helloHandler)

	r.Run(":8888")
}
